package web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ActionServlet extends HttpServlet {

	@Override
	protected void service(
			HttpServletRequest req, 
			HttpServletResponse res) throws ServletException, IOException {
		
		System.out.println("service();");
		
		//分析请求路径,依据分析结果调用不用的分支来处理
		
		//获取请求资源路径
		String uri = req.getRequestURI();
		System.out.println("uri"+uri);
		
		String action = 
				uri.substring(uri.lastIndexOf("/"),uri.lastIndexOf("."));
		System.out.println("action"+action);
		req.setCharacterEncoding("utf-8");
		res.setContentType("text/html;charset=utf-8");
		PrintWriter pw = res.getWriter();
		
		if(action.equals("/check")){
			String adminCode=req.getParameter("adminCode");
			System.out.println("adminCode:"+adminCode);
			if("king".equals(adminCode)){
				pw.println("账号已经存在");
			}else{
				pw.println("可以使用");
			}
			
			
		}else if("/gender".equals(action)){
			int a=(int)(Math.random()*1000);
			pw.println(a);
			System.out.println(a);
		}
	
	}
	
	
	


}























